#ifndef TIMECALLBACK_H
#define TIMECALLBACK_H
#include <pthread.h>

extern void addCallback(int clientindex, int timeID, byteArrays param, int second);
extern void addCallback(int clientindex, int timeID, byteArrays param);
extern void addCallback(int clientindex, int timeID);
extern void cancelCallBack(int clientindex, int timeID);
extern void cancelCallBackPlayer(int clientindex);
extern int getCallbackRemain(int clientindex, int timeID);

#define TIMER_SAVEDATA 1
#define TIMER_SYNCPOS 2

struct TimeoutInfo {
	int id;
	std::string name;
	int interval;
	std::string comment;
	int recvproc;
	TimeoutInfo() {id = 0;name = comment = "";interval = 0;recvproc = 0;}
	TimeoutInfo(int i, std::string n, int t, std::string c, int r) {id = i;name = n;interval = t;comment = c;recvproc = r;}
};

extern std::map<int, TimeoutInfo> timeoutlist;

class timecallback
{
private:
	timecallback();
	static void* tick(void*);
public:
	~timecallback();

public:
	static timecallback* instance();
	void addCallBack(int clientindex, int timeID, byteArrays param, int second);
	void cancelCallBack(int clientindex, int timeID);
	void cancelCallBackPlayer(int clientindex);
	int getCallbackRemain(int clientindex, int timeID);
private:
	static timecallback* m_instance;
	pthread_t m_th;
	pthread_attr_t m_attr;
	static pthread_mutex_t m_mutex;
};

#endif // TIMECALLBACK_H
